﻿class FieldValidator {

    static validateText(text, minLength, maxLength) {
        var errors = [];

        if (text.length < minLength) {
            errors.push("Required at least " + minLength + " symbols");
        }

        if (text.length > maxLength) {
            errors.push("Required no more than " + minLength + " symbols.");
        }

        return errors;
    }

    static validatePassword(text, minLength, maxLength) {
        var errors = this.validateText(text, minLength, maxLength);

        //todo

        return errors;
    }

    static isEqualPasswords(objA, objB) {
        if (objA === objB) {
            return [];
        }

        return ["Passwords are not equal."];
    }

    static validateEmail(email) {

        //todo

        return [];
    }

    static hasErrors(errors) {
        for (var f in errors) {
            if (errors[f].length > 0) {
                return true;
            }
        }

        return false;
    }
}